package ejemplosAR;

import processing.core.*;
import processing.video.*;
import jp.nyatla.nyar4psg.*;

public class Rotacion extends PApplet {

	private static final long serialVersionUID = 1L;
	private static final String PARA = "/Users/marthagarzon/Desktop/Juan Manuel/Workspace/ModuloSimulacion/data/camera_para.dat";
	private static final String HIRO = "/Users/marthagarzon/Desktop/Juan Manuel/Workspace/ModuloSimulacion/data/patt.hiro";
	private static final String KANJI ="/Users/marthagarzon/Desktop/Juan Manuel/Workspace/ModuloSimulacion/data/patt.kanji";

	private Capture cam;
	private MultiMarker nya_r;
	private MultiMarker nya_l;
	private PFont font=createFont("FFScala", 32);
	private int c=0;

	public void setup() {
		size(640,480,P3D);
		colorMode(RGB, 100);
		println(MultiMarker.VERSION);

		cam=new Capture(this,640,480);
		nya_l=new MultiMarker(this,width,height,PARA,new NyAR4PsgConfig(NyAR4PsgConfig.CS_LEFT_HAND,NyAR4PsgConfig.TM_NYARTK));
		nya_l.addARMarker(HIRO,80);

		nya_r=new MultiMarker(this,width,height,PARA,new NyAR4PsgConfig(NyAR4PsgConfig.CS_RIGHT_HAND,NyAR4PsgConfig.TM_NYARTK));
		nya_r.addARMarker(KANJI,80);
	}

	public void drawgrid()
	{
		pushMatrix();
		stroke(0);
		strokeWeight(2);
		line(0,0,0,100,0,0);
		textFont(font,(float) 20.0); text("X",100,0,0);
		line(0,0,0,0,100,0);
		textFont(font,(float) 20.0); text("Y",0,100,0);
		line(0,0,0,0,0,100);
		textFont(font,(float) 20.0); text("Z",0,0,100);
		popMatrix();
	}

	public void draw()
	{
		c++;
		if (cam.available()){
			cam.read();
			nya_r.detect(cam);
			nya_l.detect(cam);
			background(0);
			nya_r.drawBackground(cam);
			//right
			if(nya_r.isExistMarker(0)){
				nya_r.beginTransform(0);
				fill(0,0,255);
				drawgrid();
				translate(0,0,20);
				rotate((float)c/100);
				box(40);
				nya_r.endTransform();
			}
			//left
			if((nya_l.isExistMarker(0))){
				nya_l.beginTransform(0);
				fill(0,255,0);
				drawgrid();
				translate(0,0,20);
				rotate((float)c/100);
				box(40);
				nya_l.endTransform();
			}
		}
	}

}